package com.order.www;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-01-09
 * Time:21:18
 */
class ListNode{
    public int val;
    public ListNode next = null;
    public ListNode(int val){
        this.val = val;
    }
}
//反转链表
public class NC78 {

        public ListNode ReverseList(ListNode head) {
            if(head == null)return null;
            ListNode cur = head.next;
            ListNode prev = head;
            head.next = null;
            //反转链表
            while(cur != null){
                ListNode curNext = cur.next;//把要反转的下一个节点记录下来方便向下走
                cur.next = prev;//更换next的值
                prev = cur;//反转完成  向下走
                cur = curNext;
            }


            return prev;
        }
}
